home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / missile.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  4KB  |  158 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12.  
  13. static int ctrld;
  14. static int h_pos, v_pos;
  15.  
  16. extern int missile_flipscreen;
  17.  
  18. int  missile_video_r (int address);
  19. void missile_video_w (int address, int data);
  20. void missile_video_mult_w (int address, int data);
  21.  
  22. WRITE_HANDLER( missile_palette_w );
  23. void missile_flip_screen (void);
  24.  
  25.  
  26. /********************************************************************************************/
  27. READ_HANDLER( missile_IN0_r )
  28. {
  29.     if (ctrld)    /* trackball */
  30.     {
  31.         if (!missile_flipscreen)
  32.               return ((readinputport(5) << 4) & 0xf0) | (readinputport(4) & 0x0f);
  33.         else
  34.               return ((readinputport(7) << 4) & 0xf0) | (readinputport(6) & 0x0f);
  35.     }
  36.     else    /* buttons */
  37.         return (readinputport(0));
  38. }
  39.  
  40.  
  41. /********************************************************************************************/
  42. void missile_init_machine(void)
  43. {
  44.     h_pos = v_pos = 0;
  45. }
  46.  
  47.  
  48. /********************************************************************************************/
  49. WRITE_HANDLER( missile_w )
  50. {
  51.     int pc, opcode;
  52.     int address = offset + 0x640;
  53.  
  54.     pc = cpu_getpreviouspc();
  55.     opcode = cpu_readop(pc);
  56.  
  57.     /* 3 different ways to write to video ram - the third is caught by the core memory handler */
  58.     if (opcode == 0x81)
  59.     {
  60.         /*     STA ($00,X) */
  61.         missile_video_w (address, data);
  62.         return;
  63.     }
  64.     if (address <= 0x3fff)
  65.     {
  66.         missile_video_mult_w (address, data);
  67.         return;
  68.     }
  69.  
  70.     /* $4c00 - watchdog */
  71.     if (address == 0x4c00)
  72.     {
  73.         watchdog_reset_w (address, data);
  74.         return;
  75.     }
  76.  
  77.     /* $4800 - various IO */
  78.     if (address == 0x4800)
  79.     {
  80.         if (missile_flipscreen != (!(data & 0x40)))
  81.             missile_flip_screen ();
  82.         missile_flipscreen = !(data & 0x40);
  83.         coin_counter_w (0, data & 0x20);
  84.         coin_counter_w (1, data & 0x10);
  85.         coin_counter_w (2, data & 0x08);
  86.         osd_led_w (0, ~data >> 1);
  87.         osd_led_w (1, ~data >> 2);
  88.         ctrld = data & 1;
  89.         return;
  90.     }
  91.  
  92.     /* $4d00 - IRQ acknowledge */
  93.     if (address == 0x4d00)
  94.     {
  95.         return;
  96.     }
  97.  
  98.     /* $4000 - $400f - Pokey */
  99.     if (address >= 0x4000 && address <= 0x400f)
  100.     {
  101.         pokey1_w (address, data);
  102.         return;
  103.     }
  104.  
  105.     /* $4b00 - $4b07 - color RAM */
  106.     if (address >= 0x4b00 && address <= 0x4b07)
  107.     {
  108.         int r,g,b;
  109.  
  110.  
  111.         r = 0xff * ((~data >> 3) & 1);
  112.         g = 0xff * ((~data >> 2) & 1);
  113.         b = 0xff * ((~data >> 1) & 1);
  114.  
  115.         palette_change_color(address - 0x4b00,r,g,b);
  116.  
  117.         return;
  118.     }
  119.  
  120.     logerror("possible unmapped write, offset: %04x, data: %02x\n", address, data);
  121. }
  122.  
  123.  
  124. /********************************************************************************************/
  125.  
  126. unsigned char *missile_video2ram;
  127.  
  128. READ_HANDLER( missile_r )
  129. {
  130.     int pc, opcode;
  131.     int address = offset + 0x1900;
  132.  
  133.     pc = cpu_getpreviouspc();
  134.     opcode = cpu_readop(pc);
  135.  
  136.     if (opcode == 0xa1)
  137.     {
  138.         /*     LDA ($00,X)  */
  139.         return (missile_video_r(address));
  140.     }
  141.  
  142.     if (address >= 0x5000)
  143.         return missile_video2ram[address - 0x5000];
  144.  
  145.     if (address == 0x4800)
  146.         return (missile_IN0_r(0));
  147.     if (address == 0x4900)
  148.         return (readinputport (1));
  149.     if (address == 0x4a00)
  150.         return (readinputport (2));
  151.  
  152.     if ((address >= 0x4000) && (address <= 0x400f))
  153.         return (pokey1_r (address & 0x0f));
  154.  
  155.     logerror("possible unmapped read, offset: %04x\n", address);
  156.     return 0;
  157. }
  158.